package optimizers.ganeat.bistableswitch;

import java.awt.GridLayout;
import java.util.Map;
import java.util.Random;

import javax.swing.JPanel;

import optimizers.commons.GAConstants;
import optimizers.commons.RunConfig;
import optimizers.ganeat.Connection;
import optimizers.ganeat.Constants;
import optimizers.ganeat.Individual;
import optimizers.ganeat.Node;

import visualization.PlotExpData;

import model.Input;
import model.OligoSystemComplex;
import model.OligoSystemGeneral;

import fitness.BistableFitness;
import fitness.BistableResult;
import fitness.FitnessResult;
import fitness.NANDResult;

public class IndividualBistableSwitch extends Individual {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public IndividualBistableSwitch(Map<String, Integer> innovations,
			Map<String, String> nodeNames, int geneIndex, int indivIndex, RunConfig config) {
		super(innovations, nodeNames, geneIndex, indivIndex, config);
		// TODO Auto-generated constructor stub
	}

	public void evaluateFitness() {
		BistableFitness fitnessEvaluator = new BistableFitness();
		BistableResult result = fitnessEvaluator
				.evaluateFitness(getOligoModel());
		this.fitnessResult = result;
	}


	public double[][] getSequenceConcentration(int nSimpleSequences) {
		double[][] seqConcentration = new double[nSimpleSequences + 1][nSimpleSequences];
		for (int i = 0; i < nSimpleSequences; ++i) {
			seqConcentration[0][i] = this.config.seqC.minValue;
		}
		seqConcentration[0][3] = this.config.seqC.maxValue;
		return seqConcentration;
	}

	@Override
	public JPanel displayTimeSereis() {
		// return null;

		JPanel panel = new JPanel();
		GridLayout grid = new GridLayout(2, 1);
		panel.setLayout(grid);
		grid.setColumns(1);

		OligoSystemGeneral oligoModel = getOligoModel();

		Input input1 = new Input(oligoModel.nameToInt.get("i1"),
				Constants.inputAmmount, Integer.MAX_VALUE);
		Input input2 = new Input(oligoModel.nameToInt.get("i2"), 0,
				Integer.MAX_VALUE);
		Input input3 = new Input(0, 0, Integer.MAX_VALUE);
		Input[] inputs = new Input[] { input1, input2, input3 };
		double[][] timeSeriesWithInput1 = oligoModel
				.getTimeSeriesWithInputComplexModel(inputs);

		input2.ammount = Constants.inputAmmount;

		double[][] timeSeriesWithInput2 = oligoModel
				.getTimeSeriesWithInputComplexModel(inputs);
		String[] seqNames = new String[timeSeriesWithInput2.length];
		for (int i = 0; i < timeSeriesWithInput2.length; i++) {
			seqNames[i] = oligoModel.intToName.get(i);
			if (seqNames[i] == null)
				seqNames[i] = "inh" + i;
		}
		final PlotExpData demo = new PlotExpData("Generation "
				+ this.generationIndex + " Index " + this.individualIndex,
				timeSeriesWithInput1, seqNames, "Time", "Expression");
		final PlotExpData demo2 = new PlotExpData("Generation "
				+ this.generationIndex + " Index " + this.individualIndex,
				timeSeriesWithInput2, seqNames, "Time", "Expression");
		panel.add(demo);
		panel.add(demo2);
		return panel;

	}

}
